﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PluginInterFace.BLL;

namespace PickExperts2.form
{
    public partial class fmPickHistory : Form
    {
        public fmPickHistory()
        {
            InitializeComponent();
        }

        private void fmPickHistory_Load(object sender, EventArgs e)
        {
            Init("");
        }

        private void Init(string 期号)
        {
            ssq_pick ssp = new ssq_pick();
            Class.main cm = new Class.main();
            cm.showWaitForm();
            rowMergeView1.DataSource = ssp.GetList(期号).Tables[0].DefaultView;
            rowMergeView1.ColumnHeadersHeight = 40;
            rowMergeView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            rowMergeView1.AddSpanHeader(0, 2, "自选期号与号码");
            rowMergeView1.AddSpanHeader(2, 7, "开奖结果");
            rowMergeView1.Columns[0].DefaultCellStyle.BackColor = Color.Yellow;
            rowMergeView1.Columns[1].DefaultCellStyle.BackColor = Color.Yellow;
            rowMergeView1.Columns[2].DefaultCellStyle.BackColor = Color.Red;
            rowMergeView1.Columns[3].DefaultCellStyle.BackColor = Color.Red;
            rowMergeView1.Columns[4].DefaultCellStyle.BackColor = Color.Red;
            rowMergeView1.Columns[5].DefaultCellStyle.BackColor = Color.Red;
            rowMergeView1.Columns[6].DefaultCellStyle.BackColor = Color.Red;
            rowMergeView1.Columns[7].DefaultCellStyle.BackColor = Color.Red;
            rowMergeView1.Columns[8].DefaultCellStyle.BackColor = Color.Blue;
            //
            rowMergeView1.Columns.Add("zhongj","中奖信息");
            for(int i=0;i<rowMergeView1.Rows.Count-1;i++)
            {
                rowMergeView1.Rows[i].Cells[9].Value = checkZj(rowMergeView1.Rows[i].Cells[1].Value.ToString(),
                                                               rowMergeView1.Rows[i].Cells[2].Value.ToString() + " " +
                                                               rowMergeView1.Rows[i].Cells[3].Value.ToString() + " " +
                                                               rowMergeView1.Rows[i].Cells[4].Value.ToString() + " " +
                                                               rowMergeView1.Rows[i].Cells[5].Value.ToString() + " " +
                                                               rowMergeView1.Rows[i].Cells[6].Value.ToString() + " " +
                                                               rowMergeView1.Rows[i].Cells[7].Value.ToString() + ":" +
                                                               rowMergeView1.Rows[i].Cells[8].Value.ToString());
                if (rowMergeView1.Rows[i].Cells[9].Value.ToString().IndexOf("未中奖") == -1 && rowMergeView1.Rows[i].Cells[9].Value.ToString() != "")
                    rowMergeView1.Rows[i].DefaultCellStyle.ForeColor = Color.Orange;
            }
            rowMergeView1.Columns[9].DefaultCellStyle.BackColor = Color.Cornsilk;
            cm.closeWaitForm();
        }

        private string checkZj(string pStr,string rStr)
        {
            string retStr = "";
            string[] aStr,bStr;
            int num;
            string tmp;
            aStr = pStr.Split(':');//自选红0,蓝1
            bStr = rStr.Split(':');//结果红0,蓝1
            num = 0;
            if (rStr.Trim() == ":")
                return "";
            foreach(var a in bStr[0].Split(' '))
            {
                tmp = a.PadLeft(2, '0');
                if (aStr[0].IndexOf(tmp) > -1 && a.ToString() != "")
                    num++;
            }
            retStr = num.ToString() + "+";
            num = 0;
            foreach (var a in bStr[1].Split(' '))
            {
                tmp = a.PadLeft(2, '0');
                if (aStr[1].IndexOf(tmp) > -1 && a.ToString() != "")
                    num++;
            }
            if (num > 0)
                retStr += "1";
            else
                retStr += "0";
            return retStr + " " + checkJD(retStr);
        }

        private string checkJD(string zStr)
        {
            string tmp = "";
            if (zStr == "")
                return "";
            switch(zStr)
            {
                case "6+1":
                    tmp = "1等奖,?元";
                    break;
                case "6+0":
                    tmp = "2等奖,?元";
                    break;
                case "5+1":
                    tmp = "3等奖,3000元";
                    break;
                case "5+0":
                    tmp = "4等奖,200元";
                    break;
                case "4+1":
                    tmp = "4等奖,200元";
                    break;
                case "4+0":
                    tmp = "5等奖,10元";
                    break;
                case "3+1":
                    tmp = "5等奖,10元";
                    break;
                case "0+1":
                case "1+1":
                case "2+1":
                    tmp = "6等奖,5元";
                    break;
                case "3+0":
                case "2+0":
                case "1+0":
                case "0+0":
                    tmp = "未中奖";
                    break;
                default:
                    tmp = "未知奖!!!";
                    break;
            }
            return tmp;
        }
    }
}
